package com.cs.pk.codestriker;

import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.cs.pk.Activator;
import com.cs.pk.interfaces.PopulateInterface;
import com.cs.pk.utils.Constants;

public abstract class CodeStriker implements PopulateInterface{
	
	private String baseUrl = null;
	
	public CodeStriker(Object obj) {
          baseUrl = Activator.getDefault().getPreferenceStore().getString(com.cs.pk.utils.Constants.CODESTRIKERURL);		
	}
	
	public Document getResourceListFromServer(String url) throws ParserConfigurationException, SAXException, IOException {
			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			Document resource = builder.parse(url);
			return resource;		
	}
	
	public String getBaseUrl() {
		if(baseUrl==null || baseUrl.trim().equals("")) {
			baseUrl = Activator.getDefault().getDefaultPreference(Constants.CODESTRIKERURL);
		}
		return baseUrl;
	}
	
	protected abstract void getPreferredList(Object payload) ;
	
	public void start(Object payload) {
		clear();
		getPreferredList(payload!=null?payload.toString():"1");
    }

}
